package com.itcam.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * Author:Cammy.Wu
 * Date:2024-06-28
 * Description:Filter快速入门
 */

@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override
    // 初始化方法,Web服务器启动，创建Filter时调用，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    // 拦截到请求时，调用该方法，可调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截方法执行了，拦截到请求...");
        filterChain.doFilter(servletRequest, servletResponse); // 放行
    }

    @Override
    // 销毁方法，服务器关闭时调用，只调用一次
    public void destroy() {
        Filter.super.destroy();
    }
}
